package com.helloworld.chat.service.impl;

import com.google.gson.Gson;
import com.helloworld.chat.dao.GroupDao;
import com.helloworld.chat.entity.Group;
import com.helloworld.chat.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by xdzy on 2017/6/28.
 */
@Service
@Transactional
public class GroupServiceImpl implements GroupService {
    private GroupDao groupDao;
    @Autowired
    public void setGroupDao(GroupDao groupDao) {
        this.groupDao = groupDao;
    }
    @Override
    @Transactional
    public void addGroup(Group group) {
        groupDao.addGroup(group);
    }

    @Override
    public Group getGroup(int gid) {
        return null;
    }

    @Override
    public List<Group> getGroupList(int uid) {
        return groupDao.getGroupList(uid);
    }

    @Override
    @Transactional(readOnly = true)
    public String getGroupList_JSON(int uid) {
        List<Group> list=groupDao.getGroupList(uid);
        return new Gson().toJson(list);
    }
    void delete(int id){
        //Group group=groupDao.getxxx(id);
        //String groupName=group.getName();
        //判断是否为默认分组，是的话return
        //group.getfriends();
        //groupDao.delete(group);
    }
}
